import http from "@/utils/http.ts";
import {R} from "@/api/common.ts";
import { ProvinceHistory} from "@/api/province.ts";
import {AxiosResponse} from "axios";
import {Base, Quality} from "@/api/baseQuality.ts";

enum Router {
    areas = "areas",
    history = "areas/history",
    health = "areas/health",
    predict="areas/predict",
}

export interface Area {
    id: number;
    cityCode: number;
    cityName: string;
    provinceId: number;
    cityJc: string;
    longitude: string;
    latitude: string;
}

export interface Weather {
    cityCode: number;
    publishTime: string;
    rain: number;
    temperature: number;
    temperatureDiff: number;
    airPressure: number;
    direct: string;
    degree: number;
    power: string;
    speed: number;
    info: string;
}

export interface AreaQuality extends Quality{
    cityCode: number;
}

interface History {
    quality: AreaQuality[];
}

export function getAreas() {
    return http<R<Area[]>>({
        url: Router.areas,
        method: "get"
    })
}

export function getAreaHistory(data: ProvinceHistory): Promise<AxiosResponse<R<History>>> {
    return http<R<History>>({
        url: Router.history,
        method: "post",
        data
    })
}

export function getAreaHealth(id: number): Promise<AxiosResponse<R<History>>> {
    return http<R<History>>({
        url: `${Router.health}/${id}`,
        method: "get",
    })
}

export function getAreaPredict(id: number) {
    return http<R<Base[]>>({
        url: `${Router.predict}/${id}`,
        method:"get"
    })
}

export function getAreaRealTime() {
    return http<R<AreaQuality[]>>({
        url: "areas/realTime",
        method: "get"
    })
}